package navigation.results.filter;

import org.htmlparser.Node;
import org.htmlparser.NodeFilter;
import org.htmlparser.nodes.TagNode;

public class ContainsInAttribute implements NodeFilter {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String attribute;
	private String contained;

	public ContainsInAttribute(String attribute, String contained) {
		this.attribute = attribute;
		this.contained = contained.toLowerCase();
	}

	@Override
	public boolean accept(Node node) {
		
		if (node instanceof TagNode){
			TagNode tn = (TagNode)node;
			
			String val = tn.getAttribute(attribute);
			
			if (val == null)
				return false;
			
			return val.toLowerCase().contains(contained);
			
		}
		return false;
	}

}
